package 删除相邻数字的最大分数;

import java.util.Scanner;

public class Main {
    static int N = 100010, M = 10010;
    static int[] f = new int[N];
    static int[] g = new int[N];
    static int[] st = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            int a = in.nextInt();
            st[a] += a;
        }
        for (int i = 1; i <= M; i++) {
            f[i] = g[i - 1] + st[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        System.out.println(Math.max(f[M], g[M]));
    }
}
